package br.com.android.financas.adapter;

import java.text.NumberFormat;
import java.util.List;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
import br.com.android.financas.DiaBase;
import br.com.android.financas.R;

public class DiaBaseAdapter extends ArrayAdapter<DiaBase> {

	private Activity activity;

	public DiaBaseAdapter(Context context, int textViewResourceId, List<DiaBase> items) {
		super(context, textViewResourceId, items);
		this.activity=(Activity) context;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View v = convertView;
		if (v == null) {

			LayoutInflater vi =activity.getLayoutInflater(); //getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			v = vi.inflate(R.layout.poupanca_item, null);
		}
		DiaBase diaBase = getItem(position);

		TextView dia = (TextView) v.findViewById(R.listaItemPoupanca.dia);
		TextView valor = (TextView) v.findViewById(R.listaItemPoupanca.valor);

		dia.setText(diaBase.getData().toString("dd"));
		valor.setText(NumberFormat.getCurrencyInstance().format(diaBase.getValor()));
		return v;
	}
}